|
Radar Host Communication library
2020.08.13
|
The communication protocol is a generic protocol to exchange messages with microcontroller based devices over a generic byte stream connection (typically a virtual serial port over USB). The communication is always initiated by the host, while the connected microcontroller device responds to messages received from the host.
The protocol defines two types of messages, payload messages and status messages. A payload message contains a block of data with arbitrary size and meaning. A status message contains a 16 bit status code. Messages from the host to the device are always payload messages. Whenever the device receives a payload message from the host, it responds with one (and only one) status message. The device may also send an arbitrary number of additional payload messages preceding that status message. Once the device has sent the status message, it won't send any more messages until it receives a new message from the host.
Each message from the host to the device is addressed to a certain logical endpoint and each message from the device to the host is sent from a logical endpoint. The number of logical endpoints is defined by the device. Endpoints are continuously enumerated starting with 1. At least one logical endpoint is always present. Endpoints are used to define functional groups in the device.
Each logical endpoint is of a defined type, which defines the meaning of the message payload exchanged with that endpoint. Additionally each endpoint has a version number that allows to distinguish between slight modifications of the endpoints set of known messages. The host can query type and version of the endpoints present in the device.
All data received from the connected device is returned through callbacks. For each message type that can be received from the device, a separate callback function type is defined.
The user must register the callback function for each message type. If no callback function is registered the received message is ignored. Additionally the user can provide a data context pointer for each callback function that will be forwarded with any call to that function.
Example for Endpoint enumeration.